The present invention covers a scheme for rounding operands of varying lengths. An operand is defined as a number on which a mathematical operation is performed. Rounding an operand deletes one or more of the least significant digits and adjusts the retained part in accordance with some specified rule.
The present invention is incorporated in the architecture of the Intel 80586 microprocessor, also known as the 586 processor. Intel, 80586, and 586 are trademarks of Intel Corporation.
One purpose for rounding is to reduce the number of digits in the operand so that the rounded operand can fit within the word size of the microprocessor. Another purpose of rounding is to remedy the accuracy associated with the microprocessor's floating point operations. Floating point notation is a method of writing numeric quantities by using a characteristic and a mantissa. The characteristic represents the integral value of the number, and the mantissa represents the decimal value of the number. For example, the number 6.3124 is comprised of a characteristic of 6 and a mantissa of 3124.
In many situations, the result of a floating point operation exceeds the microprocessor's word size. For example, the addition of two n bit numbers might result in a sum of n+1 bits. Consequently, an overflow results if the word size is only n-bits long. To make the overflow fit, the number must be shifted one position to the right, the least significant bit (LSB) is deleted, and the exponent is increased. In order to dispose of the LSB while still preserving accurate results, the number is rounded according to one of several rounding methods.
Yet another reason for rounding is to scale the mantissa length to certain precisions. The longer the mantissa length, the more precise it becomes. However, the trade off is that calculations take longer because more bits are being manipulated. Commonly, precisions are adopted according to the specifications set forth in Institute Electrical and Electronic Engineers (IEEE) standard 754 . The standard specifies four precisions: single, single extended, double, and double extended. Implementations are not required to have all four precisions.
By way of illustration, single precision is 24 bits in length. Double precision consists of 53 bits and extended precision consists of 64 bits. Thus, if the user selects single precision, every bit trailing LSB "43" (bits 42-0 of a 68 bit number) is deleted and set to "0". The LSB is rounded depending upon the rounding method chosen. Likewise, if the user selects double precision, the LSB is bit "14" and trailing bits "13-0" are set to zero. The appropriate rounding is then implemented. The same procedure occurs if extended precision is selected. The only difference is that the LSB is bit "3" and bits "2-0" are set to "0". Again, the appropriate rounding is performed. Accordingly, what is needed is a method to round a binary number based on the microprocessor word size, overflow condition, and specified precision formats.
Once it is determined that a number needs to be rounded, a rounding method must then be selected. Some of the more common rounding methods include: 1) chop, 2) roundup, 3) round down, and 4) round to nearest/even. Thus, a means to round a binary number according to the rounding mode is necessary.
In the prior art, one method for rounding was to implement a special adder which could add a "1" to any desired bit position. Another method in which rounding was implemented was to store rounding coefficients within a ROM look-up table. Thus, depending on the rounding mode, rounding calculations of whether to add a "1" or not, and the bit position to be rounded (i.e., precision), the special adder could add a "1" to a designated position accordingly or the appropriate coefficient is pulled from the ROM and added to the binary number. However, both methods mentioned above have a drawback in that they require the capability of adding a "1" to any one of several different bit positions. Hence, a method is needed to simplify and make the rounding operation faster by adding a "1" (if so required) to only one specified bit position under all circumstances.
Another problem associated with the prior art of rounding is that the rounding calculations had to be done first to determine whether to add a "1" or not. Next, the bit position must be determined. Then, the addition occurs, if so required. Typically, this process takes approximately seven clock cycles to implement. Consequently, a method is needed to process all three steps in parallel so that the entire process takes only one clock cycle.